package com.example.demo.controller;


import com.example.demo.common.Result;
import com.example.demo.entity.ShopCart;
import com.example.demo.entity.User;
import com.example.demo.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;



@Api(tags = "用户管理模块",value = "用户管理")
@RestController
@RequestMapping("/api/user")
public class UserController {
    @Autowired
    UserService userService;

    /**
     * 用户登录;
     * @param user 封装的用户名以及用户密码;
     * @return  返回User的所有信息;
     */
    @PostMapping ( "/UserLogin")
    @ApiOperation(value = "用户登录",httpMethod = "POST")
    public Result<User> UserLogin(
            @RequestBody User user
    ){
        System.out.println(user);
        User users= userService.UserLogin(user);
        if(users!=null){
            return Result.success("登录成功",users);
        }
        return Result.fail(404,"用户名或者密码错误",null);
    }

    /**
     * 查看购物车中所有商品信息;
     * @param userId  传入当前用户Id
     * @return 返回购物车;
     */
    @GetMapping("/ShopCart")
    @ApiOperation(value = "用户购物车详情",httpMethod = "GET")
    public Result<ShopCart> UserShopCartInformation(@RequestParam("id") Integer userId){
        ShopCart shopCart= userService.UserShopCartInformation(userId);
        return Result.success("购物车详情如下:",shopCart);
    }
}
